package com.dogsong.liteflow.editor.config;

import com.dogsong.liteflow.editor.controller.BizController;
import com.dogsong.liteflow.editor.controller.GenerateELController;
import com.dogsong.liteflow.editor.parser.factory.ExpressParserFactory;
import com.dogsong.liteflow.editor.parser.generator.ExpressGenerator;
import com.dogsong.liteflow.editor.service.BizService;
import com.dogsong.liteflow.editor.service.impl.BizServiceImpl;
import com.dogsong.liteflow.editor.service.impl.SqlBizServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@ComponentScan({"com.dogsong.liteflow.editor.parser.el"})
@Configuration
public class LiteFlowEditorAutoConfiguration {


    @ConditionalOnMissingBean(name = {"expressParserFactory"})
    @Bean
    public ExpressParserFactory expressParserFactory(){
        return new ExpressParserFactory();
    }

    @ConditionalOnMissingBean(name = {"expressGenerator"})
    @Bean
    public ExpressGenerator expressGenerator(){
        return new ExpressGenerator();
    }

    @ConditionalOnBean(name = {"expressGenerator"})
    @Bean
    public GenerateELController generateELController(){
        return new GenerateELController();
    }

    @ConditionalOnClass(name = {"com.yomahub.liteflow.parser.sql.SQLXmlELParser"})
    @Bean
    public BizService sqlBizService(){
        return new SqlBizServiceImpl();
    }

    @ConditionalOnMissingBean(value = {BizService.class})
    @Bean
    public BizService defaultBizService(){
        return new BizServiceImpl();
    }

    @ConditionalOnBean(value = {BizService.class})
    @Bean
    public BizController bizController(){
        return new BizController();
    }
}
